package exam.test11.q1;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;


public class MyTokenizerTest {

    @Test(timeout = 1000)
    public void testShortWordTokenizer() {
        String text = "i";
        MyTokenizer myTokenizer = new MyTokenizer(text);

        assertEquals("i", myTokenizer.current().getValue());
        assertEquals(Token.Type.SHORT_WORD, myTokenizer.current().getType());
    }

    @Test(timeout = 1000)
    public void testLongWordTokenizer() {
        String text = "castle";
        MyTokenizer myTokenizer = new MyTokenizer(text);

        assertEquals("castle", myTokenizer.current().getValue());
        assertEquals(Token.Type.LONG_WORD, myTokenizer.current().getType());
    }

    @Test(timeout = 1000)
    public void testEvenNumberTokenizer() {
        String text = "18";
        MyTokenizer myTokenizer = new MyTokenizer(text);

        assertEquals("18", myTokenizer.current().getValue());
        assertEquals(Token.Type.EVEN_NUMBER, myTokenizer.current().getType());
    }

    @Test(timeout = 1000)
    public void testOddNumberTokenizer() {
        String text = "17";
        MyTokenizer myTokenizer = new MyTokenizer(text);

        assertEquals("17", myTokenizer.current().getValue());
        assertEquals(Token.Type.ODD_NUMBER, myTokenizer.current().getType());
    }

    @Test(timeout = 1000)
    public void testEmailTokenizer() {
        String text = "something@gmail.com";
        MyTokenizer myTokenizer = new MyTokenizer(text);

        assertEquals("something@gmail.com", myTokenizer.current().getValue());
        assertEquals(Token.Type.EMAIL, myTokenizer.current().getType());
    }

    @Test(timeout = 1000)
    public void testUnknowTokenizer() {
        String text = "#";
        MyTokenizer myTokenizer = new MyTokenizer(text);

        assertEquals("#", myTokenizer.current().getValue());
        assertEquals(Token.Type.UNKNOWN, myTokenizer.current().getType());
    }


    @Test(timeout = 1000)
    public void testSentenceTokenizer() {
        String text = "i Am the KING of THE 10 castle. The caStle is my HOME.@# 21 foorbar@gmail.com aa@aa.ac";
        MyTokenizer myTokenizer = new MyTokenizer(text);

        assertEquals("i", myTokenizer.current().getValue());
        assertEquals(Token.Type.SHORT_WORD, myTokenizer.current().getType());

        myTokenizer.next();

        assertEquals("Am", myTokenizer.current().getValue());
        assertEquals(Token.Type.SHORT_WORD, myTokenizer.current().getType());

        myTokenizer.next();

        assertEquals("the", myTokenizer.current().getValue());
        assertEquals(Token.Type.SHORT_WORD, myTokenizer.current().getType());


        myTokenizer.next();

        assertEquals("KING", myTokenizer.current().getValue());
        assertEquals(Token.Type.SHORT_WORD, myTokenizer.current().getType());


        myTokenizer.next();

        assertEquals("of", myTokenizer.current().getValue());
        assertEquals(Token.Type.SHORT_WORD, myTokenizer.current().getType());

        myTokenizer.next();

        assertEquals("THE", myTokenizer.current().getValue());
        assertEquals(Token.Type.SHORT_WORD, myTokenizer.current().getType());


        myTokenizer.next();

        assertEquals("10", myTokenizer.current().getValue());
        assertEquals(Token.Type.EVEN_NUMBER, myTokenizer.current().getType());

        myTokenizer.next();

        assertEquals("castle", myTokenizer.current().getValue());
        assertEquals(Token.Type.LONG_WORD, myTokenizer.current().getType());


        myTokenizer.next();

        assertEquals(".", myTokenizer.current().getValue());
        assertEquals(Token.Type.UNKNOWN, myTokenizer.current().getType());

        myTokenizer.next();

        assertEquals("The", myTokenizer.current().getValue());
        assertEquals(Token.Type.SHORT_WORD, myTokenizer.current().getType());

        myTokenizer.next();

        assertEquals("caStle", myTokenizer.current().getValue());
        assertEquals(Token.Type.LONG_WORD, myTokenizer.current().getType());

        myTokenizer.next();

        assertEquals("is", myTokenizer.current().getValue());
        assertEquals(Token.Type.SHORT_WORD, myTokenizer.current().getType());


        myTokenizer.next();

        assertEquals("my", myTokenizer.current().getValue());
        assertEquals(Token.Type.SHORT_WORD, myTokenizer.current().getType());


        myTokenizer.next();

        assertEquals("HOME", myTokenizer.current().getValue());
        assertEquals(Token.Type.SHORT_WORD, myTokenizer.current().getType());

        myTokenizer.next();

        assertEquals(".", myTokenizer.current().getValue());
        assertEquals(Token.Type.UNKNOWN, myTokenizer.current().getType());

        myTokenizer.next();

        assertEquals("@", myTokenizer.current().getValue());
        assertEquals(Token.Type.UNKNOWN, myTokenizer.current().getType());


        myTokenizer.next();

        assertEquals("#", myTokenizer.current().getValue());
        assertEquals(Token.Type.UNKNOWN, myTokenizer.current().getType());

        myTokenizer.next();

        assertEquals("21", myTokenizer.current().getValue());
        assertEquals(Token.Type.ODD_NUMBER, myTokenizer.current().getType());

        myTokenizer.next();

        assertEquals("foorbar@gmail.com", myTokenizer.current().getValue());
        assertEquals(Token.Type.EMAIL, myTokenizer.current().getType());

        myTokenizer.next();

        assertEquals("aa@aa.ac", myTokenizer.current().getValue());
        assertEquals(Token.Type.EMAIL, myTokenizer.current().getType());

        myTokenizer.next();
        assertFalse(myTokenizer.hasNext());



    }
}
